package com.admin.utildada;

import java.util.HashMap;
import java.util.Map;

public class DadaUtil {
    private static boolean isOnline = false;   /** false 表示测试*/
    //private static String callbackUrl = isOnline ? "https://yc.gzcqcswl.com/api/dada/callback" : "http://kh9vyt.natappfree.cc/api/dada/callback";   /**回调接口地址*/

    /**
     * 获取城市code
     * @return
     */
    public static DadaApiResponse queryCityCode(){
        // 1.初始化配置(isOnline表示是否测试环境)
       AppConfig appConfig = new AppConfig(false);

        // ueditor.初始化service
        CityCodeService cityCodeService = new CityCodeService("");

        // 3.初始化客户端
        DadaRequestClient dadaClient = new DadaRequestClient(cityCodeService, appConfig);
        return dadaClient.callRpc();
    }

    /**
     *查询取消理由列表
     * @return
     */
    public static DadaApiResponse cancelReasons(){
        AppConfig appConfig = new AppConfig(isOnline);
        BaseService baseService = new BaseService(UrlConstant.CANCEL_REASONS,"");
        // 4.初始化客户端
        DadaRequestClient dadaClient = new DadaRequestClient(baseService, appConfig);
        return dadaClient.callRpc();
    }

    /**
     * 取消配送
     * @param orderCode
     * @param cancelReasonId
     * @return
     */
    public static DadaApiResponse cancel(String orderCode,String cancelReasonId){
        AppConfig appConfig = new AppConfig(isOnline);
        Map<String,String> map =new HashMap<>();
        map.put("order_id",orderCode);
        map.put("cancel_reason_id",cancelReasonId);
        BaseService baseService = new BaseService(UrlConstant.CANCEL_ORDER,JSONUtil.toJson(map));
        // 4.初始化客户端
        DadaRequestClient dadaClient = new DadaRequestClient(baseService, appConfig);
        return dadaClient.callRpc();
    }
}
